import { TextBox } from "./types";
/**
 * 
 * @param x 
 * @param y 
 * @param textBoxes 
 * @returns 距离最近的 TextBox 对象
 */
export function findClosestTextBox(x: number, y: number, textBoxes: TextBox[]): TextBox | null {
  if (textBoxes.length === 0) return null;

  let closestBox: TextBox | null = null;
  let minDistance = Infinity;

  for (const box of textBoxes) {
    const dx = x - box.x;
    const dy = y - box.y;
    const distance = Math.sqrt(dx * dx + dy * dy);

    if (distance < minDistance) {
      minDistance = distance;
      closestBox = box;
    }
  }

  return closestBox;
}